#include <iostream>
using namespace std;

template <typename T>
struct Node {
    // private:
    T data;
    Node* next;
    Node(T value, Node* nextnode = nullptr) : data(value), next(nextnode) {};
};

template <typename T>
class LinkList {
private:
    Node<T>* head;
public:
    LinkList() : head(nullptr) {};
    ~LinkList() {
        Clear();
    }
    void InsertHead(T value) {
        Node<T>* newnode = new Node<T>(value, head);
        head = newnode;
    }

    void Print() {
        Node<T>* temp = head;
        while (temp != nullptr) {
            cout << temp->data;
            temp = temp->next;
            if (temp != nullptr) cout << "->";
        }
        cout << endl;
    }

    void DeletHead() {
        if (head == nullptr) return;
        Node<T>* temp = head;
        head = head->next;
        delete temp;
    }

    void Clear() {
        while (head != nullptr) {
            DeletHead();
        }
    }
};

int main() {
    LinkList<int> mylist;
    mylist.InsertHead(8);
    mylist.InsertHead(9);
    mylist.InsertHead(6);
    mylist.InsertHead(4);
    mylist.Print();
    mylist.DeletHead();
    mylist.Print();
    mylist.Clear();
    mylist.Print();
    return 0;
}